import { call, put, takeLatest } from 'redux-saga/effects';
import { findCinemas } from '@/api/MaiZuo';

import { fetchCinemaList, changeCinemaList } from '../../features/cinemaSlice';

const { type } = fetchCinemaList;

function* getCinemaListSaga({ payload: cityId }) {
  const res = yield call(findCinemas, cityId);
  yield put(changeCinemaList(res.cinemas));
}

export function* watchGetCinemaList() {
  yield takeLatest(type, getCinemaListSaga);
}
